import {
  Column,
  Entity,
  JoinColumn,
  ManyToOne,
  OneToMany,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { User } from '@/user/entities/user.entity';
import { EverydayData } from '@/module/everyday-data/entities/everyday-datum.entity';
import { Weather } from '@/module/weather/entities/weather.entity';

@Entity({
  name: 'testing_machine',
})
export class TestingMachine {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({
    comment: '设备名称',
    nullable: true,
  })
  machineName: string;

  @Column({
    comment: '设备地址',
    nullable: true,
  })
  machineAddress: string;

  @Column({
    comment: '设备状态',
    nullable: true,
  })
  machineStatus: number;

  @Column({
    comment: '设备wifi',
    nullable: true,
  })
  machineWifi: number;

  @Column({
    comment: '烘干时间',
    nullable: true,
  })
  dryingTime: number = 60;

  @Column({
    comment: '拍照间隔',
    nullable: true,
  })
  photoInterval: number = 60;

  @Column({
    comment: '拍照参数',
    nullable: true,
  })
  photoSetting: string = '默认配置';

  @Column({
    comment: '预警线设置',
    default: 99,
    nullable: true,
  })
  predictNum: number = 99;

  @OneToMany(() => EverydayData, (everydayData) => everydayData.testingMachine)
  everydayDatas: EverydayData[];

  @OneToMany(() => Weather, (weather) => weather.testingMachine)
  weather: Weather[];

  @ManyToOne(() => User, (user) => user.testingMachines)
  @JoinColumn()
  user: User;
}
